package com.rms.server.Dao;

import com.rms.server.DTO.DailySalesProfitDTO;
import com.rms.server.Domain.Order;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO `order` (order_date, total_price, total_profit) VALUES (CURRENT_TIMESTAMP, #{totalPrice}, #{totalProfit})")
    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    void insertOrder(Order order);
    // 查询某个日期范围内的订单
//    @Select("SELECT * FROM `order` WHERE order_date BETWEEN #{startDate} AND #{endDate}")
//    List<Order> selectOrdersByDateRange(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
    @Select("SELECT DATE(order_date) AS orderDate, SUM(total_price) AS dailySales, SUM(total_profit) AS dailyProfit " +
            "FROM `order` " +
            "WHERE order_date BETWEEN #{startDateTime} AND #{endDateTime} " +
            "GROUP BY DATE(order_date) " +
            "ORDER BY DATE(order_date) ASC")  // 按日期升序排列
    List<DailySalesProfitDTO> findSalesProfitByDateRange(
            @Param("startDateTime") LocalDateTime startDateTime,
            @Param("endDateTime") LocalDateTime endDateTime);
}
